﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

using AjaxControlToolkit;

using SCS.Web.UI.WebControls.Dialogs;

[assembly: WebResource("AjaxDialogTemplate.MyDialog1.js", "text/javascript")]

namespace AjaxDialogTemplate
{
    /// <summary>
    /// Summary description for MyDialog1
    /// </summary>
    [RequiredScript(typeof(Dialog))]
    [ClientScriptResource("AjaxDialogTemplate.MyDialog1", "AjaxDialogTemplate.MyDialog1.js")]
    public class MyDialog1 : Dialog
    {
        private string _textboxId = "";

        protected override void OnPreRender(EventArgs e)
        {
            // set data needed for rendering
            _textboxId = this.ClientID + "_customInput";

            base.OnPreRender(e);
        }

        protected override void RenderDialogContent(HtmlTextWriter writer)
        {
            base.RenderDialogContent(writer);

            // TODO: add controls to be appear in the body of the dialog
            
            writer.AddAttribute(HtmlTextWriterAttribute.For, _textboxId);            
            writer.RenderBeginTag(HtmlTextWriterTag.Label);
            writer.Write("Enter Text:");
            writer.RenderEndTag();

            writer.Write("<br/>");

            writer.AddAttribute(HtmlTextWriterAttribute.Id, _textboxId);
            writer.RenderBeginTag(HtmlTextWriterTag.Textarea);            
            writer.RenderEndTag();

            // end customization
        }

        protected override void RenderDialogFooter(HtmlTextWriter writer)
        {
            base.RenderDialogFooter(writer);

            // TODO: add controls to be appear in the footer of the dialog. 
            //       the base control adds an OK and Cancel button.
        }

        [ExtenderControlProperty]  
        [IDReferenceProperty]   
        public virtual string ReturnElementId
        {
            get
            {
                object o = ViewState["ReturnElement"];
                return (o != null) ? (string)o : "";
            }
            set
            {
                ViewState["ReturnElement"] = value;
            }
        }

        [ExtenderControlProperty]
        public virtual string EditBoxId
        {
            get
            {
                return _textboxId;
            }
        }
    }
}